package cn.lijiguo.concurrency.part1.ch04;

/**
 * DaemonThread
 *
 * @author lijiguo
 * @date 2019/12/13 11:31
 */
public class DaemonThread {

    public static void main(String[] args) {
        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    System.out.println(Thread.currentThread().getName() + ":" + "run() start");
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName() + ":" + "run() end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        // 设置 t 线程为守护线程
        // 如果主线程结束 那么守护线程也会强制结束
        t.setDaemon(true);
        t.start();

        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());
    }
}
